//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "UKRegion.h"
using namespace Cephei::QL::Indexes;
#include <gen/QL/Indexes/Region.h>
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Indexes::CUKRegion::CUKRegion () : CRegion(CUKRegion::typeid)
{
    try
    {
#ifdef HANDLE
        _phUKRegion = NULL;
#endif
        _ppUKRegion = new boost::shared_ptr<QuantLib::UKRegion> (new QuantLib::UKRegion ( ));
        SetRegion (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Indexes::CUKRegion::CUKRegion (boost::shared_ptr<QuantLib::UKRegion>& childNative, Object^ owner) : CRegion(CUKRegion::typeid)
{
#ifdef HANDLE
	_phUKRegion = NULL;
#endif
	_ppUKRegion = &childNative;
    _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
}
Cephei::QL::Indexes::CUKRegion::CUKRegion (QuantLib::UKRegion& childNative, Object^ owner) : CRegion(CUKRegion::typeid)
{
#ifdef HANDLE
	_phUKRegion = NULL;
#endif
	_ppUKRegion = new boost::shared_ptr<QuantLib::UKRegion> (&childNative);
    _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
    _UKRegionOwner = owner;
    _RegionOwner = owner;
}

Cephei::QL::Indexes::CUKRegion::CUKRegion (CUKRegion^ copy) : CRegion(CUKRegion::typeid)
{
#ifdef HANDLE
	_phUKRegion = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppUKRegion = new boost::shared_ptr<QuantLib::UKRegion> (copy->GetShared());
        _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
    }
}
Cephei::QL::Indexes::CUKRegion::CUKRegion (System::Type^ t) : CRegion(CUKRegion::typeid)
{
#ifdef HANDLE
	_phUKRegion = NULL;
#endif
	if (!t->IsSubclassOf(CUKRegion::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Indexes::CUKRegion::CUKRegion (QuantLib::Handle<QuantLib::UKRegion>& childNative, Object^ owner)  : CRegion(CUKRegion::typeid)
{
	_phUKRegion = &childNative;
	_ppUKRegion = &static_cast<boost::shared_ptr<QuantLib::UKRegion>>(childNative.currentLink());
    _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
    _UKRegionOwner = owner;
}
Cephei::QL::Indexes::CUKRegion::CUKRegion (QuantLib::Handle<QuantLib::UKRegion> childNative)  : CRegion(CUKRegion::typeid)
{
	_phUKRegion = &childNative;
	_ppUKRegion = &static_cast<boost::shared_ptr<QuantLib::UKRegion>>(childNative.currentLink());
    _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
}
#endif
#ifdef STRUCT
Cephei::QL::Indexes::CUKRegion::CUKRegion (QuantLib::UKRegion childNative)  : CRegion(CUKRegion::typeid)
{
#ifdef HANDLE
	_phUKRegion = NULL;
#endif
	_ppUKRegion = new boost::shared_ptr<QuantLib::UKRegion> (new QuantLib::UKRegion (childNative));
    _ppRegion = new boost::shared_ptr<QuantLib::Region> (boost::dynamic_pointer_cast<QuantLib::Region> (*_ppUKRegion));
}
#endif

Cephei::QL::Indexes::CUKRegion::~CUKRegion ()
{
    if (_ppUKRegion != NULL)
    {
	    delete _ppUKRegion;
        _ppUKRegion = NULL;
    }
}
Cephei::QL::Indexes::CUKRegion::!CUKRegion ()
{
    if (_ppUKRegion != NULL)
    {
	    delete _ppUKRegion;
    }
}
QuantLib::UKRegion& Cephei::QL::Indexes::CUKRegion::GetReference ()
{
    if (_ppUKRegion == NULL) throw gcnew NativeNullException ();
	return **_ppUKRegion;
}
boost::shared_ptr<QuantLib::UKRegion>& Cephei::QL::Indexes::CUKRegion::GetShared ()
{
    if (_ppUKRegion == NULL) throw gcnew NativeNullException ();
	return *_ppUKRegion;
}
QuantLib::UKRegion* Cephei::QL::Indexes::CUKRegion::GetPointer ()
{
    if (_ppUKRegion == NULL) throw gcnew NativeNullException ();
	return &**_ppUKRegion;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::UKRegion>& Cephei::QL::Indexes::CUKRegion::GetHandle ()
{
	if (_phUKRegion == NULL)
	{
		_phUKRegion = new Handle<QuantLib::UKRegion> (*_ppUKRegion);
	}
	return *_phUKRegion;
}
#endif
bool Cephei::QL::Indexes::CUKRegion::HasNative () 
{
	return (_ppUKRegion != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Indexes::IUKRegion^ Cephei::QL::Indexes::CUKRegion_Factory::Create ()
{
    return gcnew CUKRegion ();
}
